from todo import *

import logging
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp

class ToDoList(webapp.RequestHandler):
  def get(self):
    todos = []
    
    if users.get_current_user():
      todos = ToDo.gql("WHERE author = :1 ORDER BY priority DESC", users.get_current_user())
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'

    template_values = {
      'todos': todos,
      'url': url,
      'url_linktext': url_linktext,
      }

    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))